home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / mordor_2.000 / mordor_2 / src / magic3.c < prev    next >
C/C++ Source or Header  |  1995-06-21  |  15KB  |  598 lines

  1. /*
  2.  * MAGIC3.C:
  3.  *
  4.  *    Additional spell-casting routines.
  5.  *
  6.  *    Copyright (C) 1991, 1992, 1993 Brett J. Vickers
  7.  *
  8.  */
  9.  
  10. #include "mstruct.h"
  11. #include "mextern.h"
  12.  
  13. /**********************************************************************/
  14. /*                bless                      */
  15. /**********************************************************************/
  16.  
  17. /* This function allows a player to cast a bless spell on himself or  */
  18. /* on another player, reducing the target's thaco by 1.           */
  19.  
  20. int bless(ply_ptr, cmnd, how)
  21. creature    *ply_ptr;
  22. cmd        *cmnd;
  23. int        how;
  24. {
  25.     creature    *crt_ptr;
  26.     room        *rom_ptr;
  27.     long        t;
  28.     int        fd;
  29.  
  30.     fd = ply_ptr->fd;
  31.     rom_ptr = ply_ptr->parent_rom;
  32.     t = time(0);
  33.  
  34.     if(ply_ptr->mpcur < 10 && how == CAST) {
  35.         print(fd, "Not enough magic points.\n");
  36.         return(0);
  37.     }
  38.  
  39.     if(!S_ISSET(ply_ptr, SBLESS) && how == CAST) {
  40.         print(fd, "You don't know that spell.\n");
  41.         return(0);
  42.     }
  43.     if(spell_fail(ply_ptr)) {
  44.                 if(how==CAST)
  45.                         ply_ptr->mpcur -= 10;
  46.                 return(0);
  47.         }
  48.  
  49.     /* Cast bless on self */
  50.     if(cmnd->num == 2) {
  51.  
  52.         F_SET(ply_ptr, PBLESS);
  53.         compute_thaco(ply_ptr);
  54.  
  55.         ply_ptr->lasttime[LT_BLESS].ltime = t;
  56.         if(how == CAST) {
  57.             ply_ptr->lasttime[LT_BLESS].interval = MAX(300, 1200 + 
  58.                 bonus[ply_ptr->intelligence]*600);
  59.             if(ply_ptr->class == CLERIC || 
  60.                ply_ptr->class == PALADIN)
  61.                 ply_ptr->lasttime[LT_BLESS].interval += 
  62.                 60*ply_ptr->level;
  63.             ply_ptr->mpcur -= 10;
  64.         if (F_ISSET(ply_ptr->parent_rom,RPMEXT)){
  65.                 print(fd,"The room's magical properties increase the power of your spell.\n");
  66.                 ply_ptr->lasttime[LT_BLESS].interval += 800L;
  67.             }                                
  68.         }
  69.         else
  70.             ply_ptr->lasttime[LT_BLESS].interval = 1200;
  71.  
  72.         if(how == CAST || how == SCROLL || how == WAND) {
  73.             print(fd,"Bless spell cast.\nYou feel holy.\n");
  74.             broadcast_rom(fd, ply_ptr->rom_num, 
  75.                       "%M casts a bless spell on %sself.", 
  76.                       ply_ptr,
  77.                       F_ISSET(ply_ptr, PMALES) ? "him":"her");
  78.         }
  79.         else if(how == POTION)
  80.             print(fd, "You feel holy.\n");
  81.  
  82.         return(1);
  83.     }
  84.  
  85.     /* Cast bless on another player */
  86.     else {
  87.  
  88.         if(how == POTION) {
  89.             print(fd, "You can only use a potion on yourself.\n");
  90.             return(0);
  91.         }
  92.  
  93.         cmnd->str[2][0] = up(cmnd->str[2][0]);
  94.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  95.                    cmnd->str[2], cmnd->val[2]);
  96.  
  97.         if(!crt_ptr) {
  98.             print(fd, "That player is not here.\n");
  99.             return(0);
  100.         }
  101.  
  102.         F_SET(crt_ptr, PBLESS);
  103.         compute_thaco(crt_ptr);
  104.  
  105.         crt_ptr->lasttime[LT_BLESS].ltime = t;
  106.         if(how == CAST) {
  107.             crt_ptr->lasttime[LT_BLESS].interval = MAX(300, 1200 + 
  108.                 bonus[ply_ptr->intelligence]*600);
  109.             if(ply_ptr->class == CLERIC || ply_ptr->class == 
  110.                PALADIN)
  111.                 crt_ptr->lasttime[LT_BLESS].interval += 
  112.                 60*ply_ptr->level;
  113.             ply_ptr->mpcur -= 10;
  114.         if (F_ISSET(ply_ptr->parent_rom,RPMEXT)){
  115.                 print(fd,"The room's magical properties increase the power of your spell.\n");
  116.                 crt_ptr->lasttime[LT_BLESS].interval += 800L;
  117.             }                                
  118.         }
  119.         else
  120.             crt_ptr->lasttime[LT_BLESS].interval = 1200;
  121.  
  122.         if(how == CAST || how == SCROLL || how == WAND) {
  123.             print(fd, "Bless cast on %s.\n", crt_ptr->name);
  124.             print(crt_ptr->fd, "%M casts a bless spell on you.\n%s",
  125.                   ply_ptr, "You feel holy.\n");
  126.             broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num,
  127.                        "%M casts a bless spell on %m.",
  128.                        ply_ptr, crt_ptr);
  129.             return(1);
  130.         }
  131.     }
  132.  
  133.     return(1);
  134.  
  135. }
  136.  
  137. /**********************************************************************/
  138. /*                turn                      */
  139. /**********************************************************************/
  140.  
  141. /* This function allows clerics and paladins to turn undead creatures. */
  142. /* If they succeed then the creature is either disintegrated or harmed */
  143. /* for approximately half of its hit points.                   */
  144.  
  145. int turn(ply_ptr, cmnd)
  146. creature    *ply_ptr;
  147. cmd        *cmnd;
  148. {
  149.     creature    *crt_ptr;
  150.     room        *rom_ptr;
  151.     long        i, t;
  152.     int        chance, m, dmg, fd;
  153.  
  154.     fd = ply_ptr->fd;
  155.     rom_ptr = ply_ptr->parent_rom;
  156.  
  157.     if(cmnd->num < 2) {
  158.         print(fd, "Turn whom?\n");
  159.         return(0);
  160.     }
  161.  
  162.     if(ply_ptr->class != CLERIC && ply_ptr->class != PALADIN &&
  163.        ply_ptr->class < CARETAKER) {
  164.         print(fd, "Only clerics and paladins may turn undead.\n");
  165.         return(0);
  166.     }
  167.  
  168.     crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  169.                cmnd->str[1], cmnd->val[1]);
  170.  
  171.     if(!crt_ptr) {
  172.         print(fd, "That isn't here.\n");
  173.         return(0);
  174.     }
  175.  
  176.     if(!F_ISSET(crt_ptr, MUNDED)) {
  177.         print(fd, "You may only turn undead monsters.\n");
  178.         return(0);
  179.     }
  180.  
  181.     if(F_ISSET(ply_ptr, PINVIS)) {
  182.         F_CLR(ply_ptr, PINVIS);
  183.         print(fd, "Your invisibility fades.\n");
  184.         broadcast_rom(fd, ply_ptr->rom_num, "%M fades into view.",
  185.                   ply_ptr);
  186.     }
  187.  
  188.     i = LT(ply_ptr, LT_TURNS);
  189.     t = time(0);
  190.  
  191.     if(i > t) {
  192.         please_wait(fd, i-t);
  193.         return(0);
  194.     }
  195.  
  196.     if(crt_ptr->type != PLAYER && F_ISSET(crt_ptr, MUNKIL)) {
  197.         print(fd, "You cannot harm %s.\n",
  198.             F_ISSET(crt_ptr, MMALES) ? "him":"her");
  199.         return(0);
  200.     }
  201.  
  202.     add_enm_crt(ply_ptr->name, crt_ptr);
  203.  
  204.     ply_ptr->lasttime[LT_TURNS].ltime = t;
  205.     ply_ptr->lasttime[LT_ATTCK].ltime = t;
  206.     ply_ptr->lasttime[LT_TURNS].interval = 30L;
  207.  
  208.     chance = (ply_ptr->level - crt_ptr->level)*20 +
  209.          bonus[ply_ptr->piety]*5 + (ply_ptr->class == PALADIN ? 15:25);
  210.     chance = MIN(chance, 80);
  211.  
  212.     if(mrand(1,100) > chance) {
  213.         print(fd, "You failed to turn %m.\n", crt_ptr);
  214.         broadcast_rom(fd, ply_ptr->rom_num, "%M failed to turn %m.",
  215.                   ply_ptr, crt_ptr);
  216.         return(0);
  217.     }
  218.  
  219.     if(mrand(1,100) > 90 - bonus[ply_ptr->piety]) {
  220.         print(fd, "You disintegrated %m.\n", crt_ptr);
  221.         broadcast_rom(fd, ply_ptr->rom_num, "%M disintegrated %m.",
  222.                   ply_ptr, crt_ptr);
  223.         add_enm_dmg(ply_ptr->name, crt_ptr, crt_ptr->hpcur);
  224.         die(crt_ptr, ply_ptr);
  225.     }
  226.  
  227.     else {
  228.         dmg = MAX(1, crt_ptr->hpcur / 2);
  229.         m = MIN(crt_ptr->hpcur, dmg);
  230.         crt_ptr->hpcur -= dmg;
  231.         add_enm_dmg(ply_ptr->name, crt_ptr, m);
  232.         print(fd, "You turned %m for %d damage.\n", 
  233.               crt_ptr, dmg);
  234.         broadcast_rom(fd, ply_ptr->rom_num, "%M turned %m.",
  235.                   ply_ptr, crt_ptr);
  236.         if(crt_ptr->hpcur < 1) {
  237.             print(fd, "You killed %m.\n", crt_ptr);
  238.             broadcast_rom(fd, ply_ptr->rom_num, "%M killed %m.",
  239.                       ply_ptr, crt_ptr);
  240.             die(crt_ptr, ply_ptr);
  241.         }
  242.     }
  243.  
  244.     return(0);
  245.  
  246. }
  247.  
  248. /**********************************************************************/
  249. /*                invisibility                  */
  250. /**********************************************************************/
  251.  
  252. /* This function allows a player to cast an invisibility spell on himself */
  253. /* or on another player.                               */
  254.  
  255. int invisibility(ply_ptr, cmnd, how)
  256. creature    *ply_ptr;
  257. cmd        *cmnd;
  258. int        how;
  259. {
  260.     creature    *crt_ptr;
  261.     room        *rom_ptr;
  262.     ctag        *cp;
  263.     long        t;
  264.     int        fd;
  265.  
  266.     fd = ply_ptr->fd;
  267.     rom_ptr = ply_ptr->parent_rom;
  268.     t = time(0);
  269.  
  270.     if(ply_ptr->mpcur < 15 && how == CAST) {
  271.         print(fd, "Not enough magic points.\n");
  272.         return(0);
  273.     }
  274.  
  275.     if(!S_ISSET(ply_ptr, SINVIS) && how == CAST) {
  276.         print(fd, "You don't know that spell.\n");
  277.         return(0);
  278.     }
  279.     if(spell_fail(ply_ptr)) {
  280.                 if(how==CAST)
  281.                         ply_ptr->mpcur -= 15;
  282.                 return(0);
  283.         }
  284.  
  285.     cp = rom_ptr->first_mon;
  286.     while(cp) {
  287.         if(is_enm_crt(ply_ptr->name, cp->crt)) {
  288.             print(fd, "Not in the middle of combat.\n");
  289.             return(0);
  290.         }
  291.         cp = cp->next_tag;
  292.     }
  293.  
  294.     /* Cast invisibility on self */
  295.     if(cmnd->num == 2) {
  296.  
  297.         ply_ptr->lasttime[LT_INVIS].ltime = t;
  298.         if(how == CAST) {
  299.             ply_ptr->lasttime[LT_INVIS].interval = 1200 + 
  300.                 bonus[ply_ptr->intelligence]*600;
  301.             if(ply_ptr->class == MAGE)
  302.                 ply_ptr->lasttime[LT_INVIS].interval += 
  303.                 60*ply_ptr->level;
  304.             ply_ptr->mpcur -= 15;
  305.         if (F_ISSET(ply_ptr->parent_rom,RPMEXT)){
  306.                 print(fd,"The room's magical properties increase the power of your spell.\n");
  307.                 ply_ptr->lasttime[LT_INVIS].interval += 600L;
  308.             }                                
  309.         }
  310.         else
  311.             ply_ptr->lasttime[LT_INVIS].interval = 1200;
  312.  
  313.         if(how == CAST || how == SCROLL || how == WAND) {
  314.             print(fd,"Invisibility spell cast.\n");
  315.             broadcast_rom(fd, ply_ptr->rom_num, 
  316.                       "%s cast invisibility on %sself.", 
  317.                       ply_ptr->name,
  318.                       F_ISSET(ply_ptr, PMALES) ? "him":"her");
  319.         }
  320.         else if(how == POTION)
  321.             print(fd, "You turn invisible.\n");
  322.  
  323.         F_SET(ply_ptr, PINVIS);
  324.  
  325.         return(1);
  326.     }
  327.  
  328.     /* Cast invisibility on another player */
  329.     else {
  330.  
  331.         if(how == POTION) {
  332.             print(fd, "You can only use a potion on yourself.\n");
  333.             return(0);
  334.         }
  335.  
  336.         cmnd->str[2][0] = up(cmnd->str[2][0]);
  337.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  338.                    cmnd->str[2], cmnd->val[2]);
  339.  
  340.         if(!crt_ptr) {
  341.             print(fd, "That player is not here.\n");
  342.             return(0);
  343.         }
  344.  
  345.         crt_ptr->lasttime[LT_INVIS].ltime = t;
  346.         if(how == CAST) {
  347.             crt_ptr->lasttime[LT_INVIS].interval = 1200 + 
  348.                 bonus[ply_ptr->intelligence]*600;
  349.             if(ply_ptr->class == MAGE)
  350.                 crt_ptr->lasttime[LT_INVIS].interval += 
  351.                 60*ply_ptr->level;
  352.             ply_ptr->mpcur -= 15;
  353.         if (F_ISSET(ply_ptr->parent_rom,RPMEXT)){
  354.                 print(fd,"The room's magical properties increase the power of your spell.\n");
  355.                 crt_ptr->lasttime[LT_INVIS].interval += 600L;
  356.             }                                
  357.         }
  358.         else
  359.             crt_ptr->lasttime[LT_INVIS].interval = 1200;
  360.  
  361.         if(how == CAST || how == SCROLL || how == WAND) {
  362.             print(fd, "Invisibility cast on %m.\n", crt_ptr);
  363.             print(crt_ptr->fd, 
  364.                   "%M casts an invisibility spell on you.\n",
  365.                   ply_ptr);
  366.             broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num,
  367.                        "%M casts an invisibility spell on %m.",
  368.                        ply_ptr, crt_ptr);
  369.             F_SET(crt_ptr, PINVIS);
  370.             return(1);
  371.         }
  372.     }
  373.  
  374.     return(1);
  375.  
  376. }
  377.  
  378. /**********************************************************************/
  379. /*                restore                      */
  380. /**********************************************************************/
  381.  
  382. /* This function allows a player to cast the restore spell using either */
  383. /* a potion or a wand.  Restore should not be a cast-able spell because */
  384. /* it can restore magic points to full.                    */
  385.  
  386. int restore(ply_ptr, cmnd, how)
  387. creature    *ply_ptr;
  388. cmd        *cmnd;
  389. int        how;
  390. {
  391.     creature    *crt_ptr;
  392.     room        *rom_ptr;
  393.     int        fd;
  394.  
  395.     fd = ply_ptr->fd;
  396.     rom_ptr = ply_ptr->parent_rom;
  397.  
  398.     if(how == CAST && ply_ptr->class < CARETAKER) {
  399.         print(fd, "You may not cast that spell.\n");
  400.         return(0);
  401.     }
  402.  
  403.     /* Cast restore on self */
  404.     if(cmnd->num == 2) {
  405.  
  406.         ply_ptr->hpcur += dice(2,10,0);
  407.         ply_ptr->hpcur = MIN(ply_ptr->hpcur, ply_ptr->hpmax);
  408.  
  409.         if(mrand(1,100) < 34)
  410.             ply_ptr->mpcur = ply_ptr->mpmax;
  411.  
  412.         if(how == CAST || how == WAND) {
  413.             print(fd, "Restore spell cast.\n");
  414.             broadcast_rom(fd, ply_ptr->rom_num, 
  415.                       "%M casts restore on %sself.", 
  416.                       ply_ptr,
  417.                       F_ISSET(ply_ptr, PMALES) ? "him":"her");
  418.         }
  419.         else if(how == POTION)
  420.             print(fd, "You feel restored.\n");
  421.  
  422.         return(1);
  423.     }
  424.  
  425.     /* Cast restore on another player */
  426.     else {
  427.  
  428.         if(how == POTION) {
  429.             print(fd, "You can only use a potion on yourself.\n");
  430.             return(0);
  431.         }
  432.  
  433.         cmnd->str[2][0] = up(cmnd->str[2][0]);
  434.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  435.                    cmnd->str[2], cmnd->val[2]);
  436.  
  437.         if(!crt_ptr) {
  438.             print(fd, "That player is not here.\n");
  439.             return(0);
  440.         }
  441.  
  442.         crt_ptr->hpcur += dice(2,10,0);
  443.         crt_ptr->hpcur = MIN(crt_ptr->hpcur, crt_ptr->hpmax);
  444.  
  445.         if(mrand(1,100) < 34)
  446.             crt_ptr->mpcur = crt_ptr->mpmax;
  447.  
  448.         if(how == CAST || how == WAND) {
  449.             print(fd, "Restore spell cast on %m.\n", crt_ptr);
  450.             print(crt_ptr->fd, 
  451.                   "%M casts a restore spell on you.\n", ply_ptr);
  452.             broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num,
  453.                        "%M casts a restore spell on %m.",
  454.                        ply_ptr, crt_ptr);
  455.             return(1);
  456.         }
  457.     }
  458.  
  459.     return(1);
  460.  
  461. }
  462.  
  463. /**********************************************************************/
  464. /*                befuddle                  */
  465. /**********************************************************************/
  466.  
  467. int befuddle(ply_ptr, cmnd, how)
  468. creature    *ply_ptr;
  469. cmd        *cmnd;
  470. int        how;
  471. {
  472.     creature    *crt_ptr;
  473.     room        *rom_ptr;
  474.     int        fd, dur;
  475.  
  476.     fd = ply_ptr->fd;
  477.     rom_ptr = ply_ptr->parent_rom;
  478.  
  479.     if(ply_ptr->mpcur < 10 && how == CAST) {
  480.         print(fd, "Not enough magic points.\n");
  481.         return(0);
  482.     }
  483.  
  484.     if(!S_ISSET(ply_ptr, SBEFUD) && how == CAST) {
  485.         print(fd, "You don't know that spell.\n");
  486.         return(0);
  487.     }
  488.  
  489.     if(F_ISSET(ply_ptr, PINVIS)) {
  490.         F_CLR(ply_ptr, PINVIS);
  491.         print(fd, "Your invisibility fades.\n");
  492.         broadcast_rom(fd, ply_ptr->rom_num, "%M fades into view.",
  493.                   ply_ptr);
  494.     }
  495.     if(spell_fail(ply_ptr)) {
  496.                 if(how==CAST)
  497.                         ply_ptr->mpcur -= 10;
  498.                 return(0);
  499.         }
  500.  
  501.     /* Befuddle self */
  502.     if(cmnd->num == 2) {
  503.  
  504.         if(how == CAST) {
  505.             dur = bonus[ply_ptr->intelligence]*2 + 
  506.                   dice(2,6,0) + (ply_ptr->class == MAGE ?
  507.                   ply_ptr->level/2 : 0);
  508.             ply_ptr->mpcur -= 10;
  509.         }
  510.         else
  511.             dur = dice(2,6,0);
  512.  
  513.         dur = MAX(5, dur);
  514.         ply_ptr->lasttime[LT_ATTCK].ltime = time(0);
  515.         ply_ptr->lasttime[LT_ATTCK].interval = dur;
  516.  
  517.         if(how == CAST || how == SCROLL || how == WAND)  {
  518.             print(fd, "You're stunned.\n");
  519.             broadcast_rom(fd, ply_ptr->rom_num, 
  520.                       "%M casts a stun spell on %sself.", 
  521.                       ply_ptr,
  522.                       F_ISSET(ply_ptr, PMALES) ? "him":"her");
  523.         }
  524.         else if(how == POTION)
  525.             print(fd, "You feel dizzy.\n");
  526.  
  527.     }
  528.  
  529.     /* Befuddle a monster or player */
  530.     else {
  531.  
  532.         if(how == POTION) {
  533.             print(fd, "You can only use a potion on yourself.\n");
  534.             return(0);
  535.         }
  536.  
  537.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  538.                    cmnd->str[2], cmnd->val[2]);
  539.  
  540.         if(!crt_ptr) {
  541.             cmnd->str[2][0] = up(cmnd->str[2][0]);
  542.             crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  543.                        cmnd->str[2], cmnd->val[2]);
  544.  
  545.             if(!crt_ptr || crt_ptr == ply_ptr || 
  546.                strlen(cmnd->str[2]) < 3) {
  547.                 print(fd, "That's not here.\n");
  548.                 return(0);
  549.             }
  550.  
  551.         }
  552.  
  553.         if(crt_ptr->type != PLAYER && F_ISSET(crt_ptr, MUNKIL)) {
  554.             print(fd, "You cannot harm %s.\n",
  555.                 F_ISSET(crt_ptr, MMALES) ? "him":"her");
  556.             return(0);
  557.         }
  558.  
  559.         if(how == CAST) {
  560.             dur = bonus[ply_ptr->intelligence]*2 + dice(2,6,0);
  561.             ply_ptr->mpcur -= 10;
  562.         }
  563.         else
  564.             dur = dice(2,5,0);
  565.  
  566.         if((crt_ptr->type == PLAYER && F_ISSET(crt_ptr, PRMAGI)) ||
  567.            (crt_ptr->type != PLAYER && (F_ISSET(crt_ptr, MRMAGI) || F_ISSET(crt_ptr, MRBEFD))))
  568.             dur = 3;
  569.         else
  570.             dur = MAX(5, dur);
  571.  
  572.         crt_ptr->lasttime[LT_ATTCK].ltime = time(0);
  573.         crt_ptr->lasttime[LT_ATTCK].interval = dur;
  574.                 crt_ptr->lasttime[LT_SPELL].ltime = time(0);
  575.         dur = MIN(10, dur);
  576.                 crt_ptr->lasttime[LT_SPELL].interval = dur;
  577.  
  578.  
  579.  
  580.         if(how == CAST || how == SCROLL || how == WAND) {
  581.             print(fd, "Stun cast on %s.\n", crt_ptr->name);
  582.             broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num,
  583.                        "%M casts stun on %m.",
  584.                        ply_ptr, crt_ptr);
  585.             print(crt_ptr->fd, 
  586.                   "%M stunned you.\n",
  587.                   ply_ptr);
  588.         }
  589.  
  590.         if(crt_ptr->type != PLAYER)
  591.             add_enm_crt(ply_ptr->name, crt_ptr);
  592.  
  593.     }
  594.  
  595.     return(1);
  596.  
  597. }
  598.